package teaMainFrame;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import com.rORM.core.MysqlQuery;

import database.LessonTable;

import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JRadioButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class CreateCourse extends JFrame {
	private LessonTable l = new LessonTable(); 
	private JPanel contentPane;
	private JTextField textField;
	private JTextField textField_2;
	private int flag;//判断学分

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					CreateCourse frame = new CreateCourse();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public CreateCourse() {
		setVisible(true);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
		setSize(450, 300);
		setLocationRelativeTo(getOwner());
		setResizable(false);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("创建课程");
		lblNewLabel.setFont(new Font("Lucida Grande", Font.PLAIN, 16));
		lblNewLabel.setBounds(175, 18, 73, 33);
		contentPane.add(lblNewLabel);
		
		JLabel label = new JLabel("请输入课程号");
		label.setFont(new Font("Lucida Grande", Font.PLAIN, 16));
		label.setBounds(46, 68, 115, 33);
		contentPane.add(label);
		
		JLabel label_1 = new JLabel("请输入课程学分");
		label_1.setFont(new Font("Lucida Grande", Font.PLAIN, 16));
		label_1.setBounds(46, 124, 150, 33);
		contentPane.add(label_1);
		
		JLabel label_2 = new JLabel("请输入课程名");
		label_2.setFont(new Font("Lucida Grande", Font.PLAIN, 16));
		label_2.setBounds(46, 187, 115, 33);
		contentPane.add(label_2);
		
		textField = new JTextField();
		textField.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			}
		});
		textField.setBounds(243, 72, 130, 26);
		contentPane.add(textField);
		textField.setColumns(10);
		
		textField_2 = new JTextField();
		textField_2.setColumns(10);
		textField_2.setBounds(243, 191, 130, 26);
		contentPane.add(textField_2);
		
		JButton button = new JButton("提交");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				l.setLessonID(Integer.parseInt(textField.getText()));
				l.setLessonName(textField_2.getText());
				l.setEachScore(flag);
				InputCourse(l);
				JOptionPane.showMessageDialog(null,"输入成功","信息提示框",JOptionPane.INFORMATION_MESSAGE);
			}
		});
		button.setBounds(311, 229, 117, 29);
		contentPane.add(button);
		
		JRadioButton radioButton = new JRadioButton("2");
		radioButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				flag = 2;
			}
		});
		
		radioButton.setBounds(214, 129, 40, 23);
		contentPane.add(radioButton);
		
		JRadioButton radioButton_1 = new JRadioButton("4");
		radioButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				flag = 4;
			}
		});
		radioButton_1.setBounds(264, 129, 45, 23);
		contentPane.add(radioButton_1);
		
		JRadioButton radioButton_2 = new JRadioButton("6");
		radioButton_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				flag = 6;
			}
		});
		radioButton_2.setBounds(309, 129, 45, 23);
		contentPane.add(radioButton_2);
		ButtonGroup b = new ButtonGroup();
		b.add(radioButton_2);
		b.add(radioButton_1);
		b.add(radioButton);
		
		JButton button_1 = new JButton(" 返回");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				setVisible(false);
			}
		});
		button_1.setBounds(150, 229, 109, 29);
		contentPane.add(button_1);
	}
	public static boolean InputCourse(LessonTable l){
		new MysqlQuery().insert(l);
		return true;
	}
}
